home *** CD-ROM | disk | FTP | other *** search
- 'FILTER.SUB -- MSDOS QuickBASIC string filter subroutines 25 June 86
- ' by David L. Poskie (608) 274-9560
- ' 7118 Raymond Rd. Madison, WI 53719
- ' Please run any suggestions, corrections, additions, or changes by me.
- ' I can be messaged on all the major Madison, WI RBBS's.
-
- '| Filter subroutines:
- '| FilterSpaceTab -- removes leading spaces & TABS in Text$
- '| FilterNonAlpha -- removes leading non-alphabetic characters in Text$
- '| FilterNonNumeric -- removes leading non-numeric characters in Text$
- '| FilterCheck -- removes what's in Check$ from front of Text$
- '| FilterCheckTail -- removes what's in Check$ from tail of Text$
- '| NOTE: The Check filters are universal, letting you remove ANY character/s.
- '|
- '| >>> See the specific routines for more information.
- '|
- '| Input: unfiltered Text$
- '| Check$ (if using FilterCheck or FilterCheckTail)
- '| Output: filtered Text$ or error message & unaltered Text$
-
- ' ________________________ FILTER SUBROUTINES __________________________
-
- ' Filter any extra leading spaces and TABs from Text$
- FilterSpaceTab:
- ' Check for null Text$ error
- GOSUB TextError
- ' Isn't this elegant ?
- WHILE ASC(Text$) = 9 _
- OR ASC(Text$) = 32
- Text$ = RIGHT$(Text$ , LEN(Text$) - 1)
- GOSUB TextError
- WEND
- GOTO FilterExit
-
- ' Filter any leading non-alphabetic characters
- FilterNonAlpha:
- ' Check for null Text$
- GOSUB TextError
- ' I love it !
- WHILE ASC(Text$) < 65 _
- OR (ASC(Text$) > 90 AND ASC(Text$) < 97) _
- OR ASC(Text$) > 122
- Text$ = RIGHT$(Text$ , LEN(Text$) - 1)
- GOSUB TextError
- WEND
- GOTO FilterExit
-
- ' Filter any leading non-number characters
- FilterNonNumeric:
- ' Prepare for possible error
- GOSUB TextError
- ' Yeah.
- WHILE ASC(Text$) < 48 _
- OR ASC(Text$) > 57
- Text$ = RIGHT$(Text$ , LEN(Text$) - 1)
- GOSUB TextError
- WEND
- GOTO FilterExit
-
- ' Filter Text$ for any leading instance of the string variable, Check$
- ' NOTE:
- ' Check$ could be a single character, making this a universal filter.
- FilterCheck:
- ' Prepare for possible error
- GOSUB TextError
- GOSUB CheckError
- ' Easy.
- WHILE LEFT$(Text$ , LEN(Check$)) = Check$
- Text$ = RIGHT$(Text$ , LEN(Text$) - LEN(Check$))
- GOSUB TextError
- WEND
- GOTO FilterExit
-
- ' Filter Text$ for any trailing instance of the string variable, Check$
- ' NOTE:
- ' Check$ could be any character/s, making this a universal filter.
- FilterCheckTail:
- ' Test for null Check$ or null Text$ errors
- GOSUB CheckError
- ' Save Text$ in case there isn't a perfect match
- Temp$ = Text$
- ' Reverse the Check$ checking
- FOR Num = LEN(Check$) TO 1 STEP -1
- IF RIGHT$(Text$ , 1) = MID$(Check$ , Num , 1) _
- THEN Text$ = LEFT$(Text$ , LEN(Text$) - 1) : _
- NEXT Num
- 'Restore Text$, if not a complete match
- IF Num > 0 THEN Text$ = Temp$
- GOSUB TextError
- GOTO FilterExit
-
- ' Error trapping local subroutines (These could be expanded).
- ' They could be used in the main program if you've $Included this file.
- ' Check for empty Check$
- CheckError:
- IF Check$ = "" _
- THEN PRINT "Check$ empty error"
- ' Check for empty Text$
- TextError:
- IF Text$ = "" _
- THEN PRINT "Text$ empty error"
-
- ' Common exit point for all filter subroutines
- FilterExit:
- RETURN
- ' >>>>> Physical EOF FILTER.SUB 25 June 86